package com.sg.file.receive.provider.util.creator;

import java.util.Random;

/**
 * Created by asus on 2018/7/13.
 */
public class RandomFileIdCreator implements IFileIdCreator {
    private Long time;
    private String idPrefix;



    public RandomFileIdCreator(Long time,String idPrefix){
        this.time = time;
        this.idPrefix = idPrefix;
    }
    /**
     * 生成文件Id，文件名称由时间戳+四位随机数
     * @return
     */
    @Override
    public String getId(){
        Random random = new Random();
        StringBuilder stringBuilder = new StringBuilder(idPrefix);
        stringBuilder.append(time.toString());
        stringBuilder.append(random.nextInt(9));
        stringBuilder.append(random.nextInt(9));
        stringBuilder.append(random.nextInt(9));
        stringBuilder.append(random.nextInt(9));
        return stringBuilder.toString();
    }
}
